<template>
  <el-dialog :visible.sync="isShow" title="分配角色" @close="closeEvent">
    <el-checkbox-group v-model="checkArr">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">
        {{ item.name }}
      </el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <div>
        <el-button @click="submit">确定</el-button>
        <el-button @click="closeEvent">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script>
import { sysUser } from '@/api/user.js'
import { sysRole, sysUserAssignRoles } from '@/api/employees.js'
export default {
  name: '',
  data() {
    return {
      checkArr: [],
      isShow: false,
      list: [],
      id: ''
    }
  },
  created() {
    this.getData()
  },
  methods: {
    async getData() {
      const res = await sysRole({ pagesize: 999 })
      // console.log(res)
      this.list = res.data.rows
    },
    async getUserInfo(id) {
      this.id = id
      const res = await sysUser(id)
      // console.log(res)
      this.checkArr = res.data.roleIds || []
    },
    closeEvent() {
      this.isShow = false
      this.checkArr = []
    },
    async submit() {
      await sysUserAssignRoles(this.id, this.checkArr)
      this.$message.success('修改成功')
      this.isShow = false
      // console.log(res)
    }
  }
}
</script>
<style scoped lang="scss"></style>
